package main

import (
	"fmt"
	"sync"
	"sync/atomic"
	"time"
)

var total struct {
	sync.Mutex
	value uint64
}

func worker(wg *sync.WaitGroup) {
	defer wg.Done()
	var i uint64
	for i = 0; i <= 100000; i++ {
		// total.Lock()
		// total.value += i
		// total.Unlock()
		atomic.AddUint64(&total.value, i)
	}
}

func main() {
	var wg sync.WaitGroup
	start_time := time.Now()
	go worker(&wg)
	go worker(&wg)

	wg.Add(2)
	wg.Wait()
	fmt.Println(total.value, time.Now().Sub(start_time))
}
